package com.fdhwws.web.domain;

import com.fdh.myjdbcutil.ColumnField;
import com.fdh.myjdbcutil.IMyEntity;
import com.fdhwws.web.util.InfoSecurityUtil;
import com.mysql.cj.util.StringUtils;

import java.sql.Timestamp;

public class ChatRoom implements IMyEntity {
    @ColumnField(type = ColumnField.Type.SET, isPrimaryKey = true)
    private Integer id;

    @ColumnField
    private String name;

    @ColumnField
    private Integer access;

    @ColumnField
    private String password;

    @ColumnField
    private Boolean valid;

    @ColumnField
    private String pic;

    @ColumnField
    private Integer createUserId;

    @ColumnField
    private Timestamp createTime;

    public ChatRoom() {
    }

    public ChatRoom(Integer id, String name, Integer access, String password, Boolean valid, String pic, Integer createUserId, Timestamp createTime) {
        this.id = id;
        this.name = name;
        this.access = access;
        this.password = password;
        this.valid = valid;
        this.pic = pic;
        this.createUserId = createUserId;
        this.createTime = createTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAccess() {
        return access;
    }

    public void setAccess(Integer access) {
        this.access = access;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getValid() {
        return valid;
    }

    public void setValid(Boolean valid) {
        this.valid = valid;
    }

    public String getPic() {
        return pic;
    }

    public void setPic(String pic) {
        this.pic = pic;
    }

    public Integer getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(Integer createUserId) {
        this.createUserId = createUserId;
    }

    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    public ChatRoom safeMode(boolean showPassword) {
        if (showPassword && !StringUtils.isNullOrEmpty(this.password)) {
            this.password = InfoSecurityUtil.decrypt(this.password);
        } else {
            this.password = null;
        }
        createUserId = null;
        createTime = null;
        return this;
    }

    public void passwordEncrypt() {
        if (this.password != null) {
            this.password = InfoSecurityUtil.encrypt(this.password);
        }
    }

    @Override
    public String toString() {
        return "ChartRoom{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", access=" + access +
                ", password='" + password + '\'' +
                ", valid=" + valid +
                ", pic='" + pic + '\'' +
                ", createUserId=" + createUserId +
                ", createTime=" + createTime +
                '}';
    }
}
